import {
    SET_SELECT,
    REMOVE_SELECT
} from './../actionsType/news_add';


export function news_add(state = {selected: []}, action) {

    switch (action.type) {
        case SET_SELECT:
            return Object.assign({},
                ...state,
                {
                    selected: [...state.selected, ...action.items]
                }
            );
        case REMOVE_SELECT:
            if (typeof action.index == 'number')
                return Object.assign({},
                    ...state,
                    {
                        selected: [
                            ...state.selected.slice(0, action.index),
                            ...state.selected.slice(action.index + 1)
                        ]
                    }
                );
            if (typeof action.id == 'number')
                return Object.assign({},
                    ...state,
                    {
                        selected: [..._.filter(state.selected, function (item) {
                            return item.id != action.id;
                        })]
                    }
                );
            return state;
        default:
            return state;
    }
}